function printOptionsForMonths(maxMonth){
	returnValue = '';
	for(i = 0; i <= maxMonth; i++){
		returnValue += '<option value="'+i+'">'+valeurMois[i]+'</option>';
	}
	return returnValue;
}

function printOptionsForLastMonths(minMonth){
	returnValue = '';
	for(i = minMonth; i <= 11; i++){
		returnValue += '<option value="'+i+'">'+valeurMois[i]+'</option>';
	}
	return returnValue;
}

$(document).ready(function() {
   // do stuff when DOM is ready
	$("#annees").change(function(){
		
		currentDate = new Date();
		currentMonth = currentDate.getMonth();
		currentYear = currentDate.getFullYear();
		
		if($(this).val() == currentYear){
			$("#mois").empty();
			$("#mois").append(printOptionsForMonths(currentMonth));
		}else if($(this).val() == currentYear - 1){
			$("#mois").empty();
			$("#mois").append(printOptionsForMonths(11));
		}else if($(this).val() == currentYear - 2){
			$("#mois").empty();
			$("#mois").append(printOptionsForMonths(11));
		}else if($(this).val() == currentYear - 3){
			$("#mois").empty();
			$("#mois").append(printOptionsForLastMonths(currentMonth));
		}
	});
 });
